package com.hserver.docker.service.impl;

import com.hserver.docker.bean.DockerUrl;
import com.hserver.docker.dao.DockerUrlMapper;
import com.hserver.docker.service.DockerUrlService;
import cn.hserver.core.ioc.annotation.Autowired;
import cn.hserver.core.ioc.annotation.Bean;

import java.util.List;
import java.util.UUID;

/**
 * @author hxm
 */
@Bean
public class DockerUrlServiceImpl implements DockerUrlService {

    @Autowired
    private DockerUrlMapper dockerUrlMapper;

    @Override
    public void add(String name, String url) {
        DockerUrl dockerUrl = new DockerUrl();
        dockerUrl.setId(UUID.randomUUID().toString());
        dockerUrl.setName(name);
        dockerUrl.setUrl(url);
        dockerUrlMapper.insert(dockerUrl);
    }

    @Override
    public List<DockerUrl> list() {
        return dockerUrlMapper.createLambdaQuery().select();
    }

    @Override
    public void remove(String id) {
        dockerUrlMapper.deleteById(id);
    }


    @Override
    public DockerUrl getById(String id){
        return dockerUrlMapper.createLambdaQuery().andEq(DockerUrl::getId, id).single();
    }

}
